﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TravelLib
{
    public static class AirportManager
    {
        private static List<Airport> _airports =new List<Airport>();

        public static List<Airport> Airports
        {
            get { return _airports; }
            set { _airports = value; }
        }

        public static Airport GetAirportByName(string name)
        {
            if (null == _airports)
                return null;
            Airport toReturn = _airports.First(x => x.Name == name);
            return toReturn;
        }

        public static Airport GetAirportByCode(string code)
        {
            if (null == _airports)
                return null;
            Airport toReturn = _airports.First(x => x.Code == code);
            return toReturn;
        }

        public static Airport GetAirportByIndex(int index)
        {
            if (null == _airports)
                return null;
            Airport toReturn = _airports.First(x => x.Index == index);
            return toReturn;
        }

        public static List<String> GetAirportNameList()
        {
            List<string> airportNameList = new List<string>();
            if (null == _airports)
                return airportNameList;
            foreach (Airport a in _airports)
            {
                airportNameList.Add(a.Name);
            }
            return airportNameList;
        }

        public static int GetNumberOfAirports()
        {
            if (null == _airports)
                return 0;
            return _airports.Count();
        }

    }
}
